//
//  MeatWholePigUIComponent.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/25.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatWholePigUIComponent.h"

@implementation MeatWholePigUIComponent

#pragma mark - setter methods

- (void)setView:(UIView *)view
{
    [view addSubview:self.shopIcon];
    [view addSubview:self.pigTypeTipLab];
    [view addSubview:self.pigTypeNOLab];
    [view addSubview:self.pigTypePriceCancelLab];
    [view addSubview:self.pigTypePriceLab];
    [view addSubview:self.checkBtn];
}


- (void)setType:(MeatFoldUILayoutType)type
{
    
    [self.shopIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(47);
        make.top.mas_equalTo(15);
        make.width.height.mas_equalTo(80);
    }];
    
    if (type == MeatFoldUILayoutType_Whole)
    {

        [self.pigTypeTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.shopIcon.mas_right).mas_offset(13);
            make.top.mas_equalTo(15);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(20);
        }];
        
        [self.pigTypeNOLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.pigTypeTipLab.mas_right).mas_offset(4);
            make.top.mas_equalTo(15);
            make.right.mas_equalTo(-30);
            make.height.mas_equalTo(20);
        }];
        
        [self.pigTypePriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.shopIcon.mas_right).mas_offset(13);
            make.top.mas_equalTo(self.pigTypeTipLab.mas_bottom).mas_offset(29);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(20);
        }];
        
        [self.pigTypePriceCancelLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.pigTypePriceLab.mas_right).mas_offset(5);
            make.top.mas_equalTo(self.pigTypePriceLab.mas_top);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(20);
        }];
        
        _checkBtn.size = CGSizeMake(48, 48);
        _checkBtn.mj_x = 0;
        _checkBtn.mj_y = 42;
    }
    
    self.pigTypeTipLab.text = @"杜洛克猪";
    self.pigTypeNOLab.text = @"HT-02";
    
    NSMutableAttributedString *aims = [@"¥1562.78" createDeleteStringByTextColor:UIColorFromRGB(0x999999) font:mFont(12)];
    self.pigTypePriceCancelLab.attributedText = aims;
    
    self.pigTypePriceLab.text = @"¥216";
}


- (void)setModel:(MeatShopRightModel *)model
{
    NSString *image = model.isChicked ?@"adopt_buy_selected" :@"meat_cart_unchecked";
    [_checkBtn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
}


- (void)setItem:(PigTypeItem *)item
{
    NSString *image = item.isChicked ?@"adopt_buy_selected" :@"meat_cart_unchecked";
    [_checkBtn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
}


#pragma mark - getter methods

- (UIImageView *)shopIcon{
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        [self addShadowAndCircleCorner:_shopIcon.layer corner:5];
        _shopIcon.image = [UIImage imageNamed:@"p1"];
    }
    return _shopIcon;
}


- (UILabel *)pigTypeTipLab{
    
    if (! _pigTypeTipLab){
        _pigTypeTipLab = [UILabel makeLabelWithText:@"" textColor:mMainColor font:mFont(12) textAliment:1];
        _pigTypeTipLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        [self addShadowAndCircleCorner:_pigTypeTipLab.layer corner:3];
    }
    return _pigTypeTipLab;
}


- (UILabel *)pigTypeNOLab{
    
    if (!_pigTypeNOLab){
        _pigTypeNOLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mFont(15) textAliment:0];
    }
    return _pigTypeNOLab;
}


- (UILabel *)pigTypePriceLab{
    
    if (!_pigTypePriceLab){
        _pigTypePriceLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0xF25C62) font:mFont(17) textAliment:0];
    }
    return _pigTypePriceLab;
}

- (UILabel *)pigTypePriceCancelLab{
    
    if (!_pigTypePriceCancelLab){
        _pigTypePriceCancelLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:0];
    }
    return _pigTypePriceCancelLab;
}


- (UIButton *)checkBtn{
    
    if (!_checkBtn) {
        _checkBtn = [UIButton makeButtonWithImageName:@"meat_cart_unchecked"];
        _checkBtn.selected = YES;
        
        _checkBtn.isNeedAnimation = YES;
        
        kWeakSelf(self);
        _checkBtn.tapBlock = ^{
            
            if (weakself.chooseCartBlock) {
                weakself.chooseCartBlock(weakself.checkBtn);
            }
        };
    }
    return _checkBtn;
}


@end
